<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>
</head>
<body>
</body>
<script>
    let oldObj = {
        name:'haha',
        age:18,
        grade:[100,90],
        family:{
            mama:'Ma'
        }
    }

    let newObj = {}
    function deepClone(newObj, oldObj){
        for( let key in oldObj){
            if( oldObj.hasOwnProperty(key)){
                let value = oldObj[key]
                if(value instanceof Array){
                    newObj[key] = []
                    deepClone(newObj[key],value)
                }else if(value instanceof Object){
                    newObj[key] = {}
                    deepClone(newObj[key],value)
                }else{
                    newObj[key] = value
                }
                
            }
        }
    }
    
    deepClone(newObj, oldObj)
    newObj.name = '嘿嘿'
    newObj.age = 30
    newObj.family.mama = '马'
    console.log(newObj)
    console.log(oldObj)
    

</script>
</html>